<template>
	<view class="container">
		<myNavigate @changecity="changecity" :cityname="cityname"></myNavigate>
		<!-- 
		<view class="sortlist">
			<myTab v-if="secCates.length>0" @tabClick="chikdClick" ref="mid" isCate border='#ee5b25' :tabs='secCates'></myTab>
		</view> -->
		<view class="goodsContain">
			<view class="goodContent">
				<block v-if="gifts.length">
					<view class="goodItem" v-for="(item,index) in gifts" :key="index" @click="toProduct(item.goodsId)">
						<image :src="item.goodsImg" class="goodsPic" mode=""></image>
						<view class="complateRow">
							<view class="comLeft" style="width: 100%;">
								<view class="goodsName">
									{{item.goodsName}}
								</view>
								<view class="price">
									<view>
										<text class="currPrice">￥{{item.shopPrice}}</text>
										<text class="thouLine">￥{{item.marketPrice}}</text>
									</view>
								</view>
								<!-- <view class="expreTitle" style="color:#ff6600">消费补贴：{{item.rebate_gg_credit}}</view> -->
								<view class="comRight">
									消费奖励<text>￥{{item.rebate_gg_credit}}</text>
								</view>
								<view class="time">
									剩余时间：<uni-countdown :day="1" :hour="1" :minute="12" :second="40" style="margin: 0;"></uni-countdown>
								</view>
								<view class="express">
								</view>
							</view>
						</view>
					</view>
				</block>
				<empty v-if="showempty" emptyText="无对应礼包"></empty>
			</view>

			<uni-load-more v-if="needLoad" :status="loadingType"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import myNavigate from "@/components/myNavigateBar/myNavigateBar.vue"
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import myTab from "@/components/scrollTab/scrollTab.vue";
	import empty from "@/components/empty.vue"
	export default {
		components: {
			myNavigate,
			myTab,
			empty,
			uniLoadMore
		},
		data() {
			return {
				goodsCatId: 0,
				page: '1',
				loading: false,
				loadingType: 'more',
				isdone: false,
				needLoad: true,
				showempty: false,
				secCates: [],
				gifts: [],
				cityname: '获取定位',
			};
		},
		onLoad() {
			// this.getsortlist();
			this.loadgiftlist()
			if (uni.getStorageSync('mycity')) {
				this.cityname = uni.getStorageSync('mycity')
			} else {

			}
		},
		methods: {
			onReachBottom() {
				let that = this;
				if (that.isdone) {
					return false;
				}
				that.loading = true;
				that.page++;
				that.loadingType = 'loading';
				that.loadgiftlist();
			},
			getsortlist() {
				let that = this;
				that.$Request.request('/api/goods/limitGiftBagCatList', 'GET').then(res => {
					if (res.status == 1) {

						that.secCates = res.data.list;
					}
				})
			},
			chikdClick(data) {
				console.log(data)
				this.goodsCatId = data.item.catId
				this.gifts = [];
				this.isdone = false;
				this.page = 1;
				this.loadgiftlist()
			},
			changecity(e) {
				this.cityname = e;
			},
			// loadgiftlist() {
			// 	let that = this;
			// 	let data = {

			// 	}
			// 	that.$Request.request('/api/goods/giftBagList', 'GET').then(res => {
			// 		that.gifts = res.data.list;
			// 	})
			// },
			loadgiftlist() {
				let that = this;
				console.log(that.isdone, '2')
				if (that.isdone) {
					return false;
				}
				// if(iswaitload){
				// 	return false;
				// }
				let data = {
					goodsCatId: '',
					latitude: getApp().globalData.globa_latitude,
					longitude: getApp().globalData.globa_longitude,
					p: that.page
				}
				that.$Request.request('/api/goods/limitGiftBagList', 'GET', data).then(res => {
					if (res.status == 1) {

						res.data.list.forEach(item => {
							that.gifts.push(item)
						})
						that.loadingType = 'more'
						if (res.data.list.length < 20) {
							that.loading = true;
							that.isdone = true;
							that.loadingType = 'noMore'
						}

						that.gifts.length == 0 ? [this.showempty = true, this.needLoad = false] : [this.showempty = false, this.needLoad =
							true
						]
					}
				}).catch(err => {
					console.log(err)
				})
			},
			toProduct(id) {
				uni.navigateTo({
					url: '../../pages/product/product?isgift=1' + '&id=' + id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.goodsName{
		
		width: 400upx;
		display: inline-block;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2 !important;
		-webkit-box-orient: vertical;
	}
	.time {
		margin: 0;
		font-size: 20upx;
		display: flex;
		align-items: center;
		margin: 10px 0px;
	}

	.sortlist {
		padding: 20upx;
		background-color: #fff;
	}

	.comRight {
		width: 120px !important;
		margin-top: 0 !important;
	}

	.uni-countdown__number {
		margin: 0 !important;
	}

	.price {
		display: flex;
		justify-content: space-between;
		margin: 10px 0px !important;
	}

	@import '../giftPackage/giftPackage.scss';
</style>
